import { cookies } from "next/headers";
import type { NextRequest } from "next/server";

import { COOKIE_ACCESS_TOKEN, COOKIE_REFRESH_TOKEN } from "@/lib/constants";

export function getServerAuthCookies(request?: NextRequest) {
  const store = request ? request.cookies : cookies();

  const accessToken = store.get(COOKIE_ACCESS_TOKEN)?.value ?? null;
  const refreshToken = store.get(COOKIE_REFRESH_TOKEN)?.value ?? null;

  return {
    accessToken,
    refreshToken,
  };
}
